<template>
  <div class="box">
    <h4>
      <a class="el-icon-arrow-left" @click="returnchange"></a>
      <span>修改密码</span>
      <a></a>
    </h4>
    <div class="box_center">
      <div class="box_center_list">
        <el-input
          placeholder="请输入新密码"
          v-model="password"
          show-password
          class="input"
          oninput="value=value.replace(/[^\da-z]/g,'')"
          maxLength="16"
        >
        </el-input>
        <el-input
          placeholder="请再次输入密码"
          v-model="rfpassword"
          show-password
          class="input"
          oninput="value=value.replace(/[^\da-z]/g,'')"
          maxLength="16"
        >
        </el-input>
        <a @click="success">完成</a>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      password: "",
      rfpassword: "",
    };
  },
  methods: {
    returnchange() {
      this.$router.push({
        path: "/me",
      });
    },
    success() {
      if (this.password != this.rfpassword) return;
      this.$http
        .post("/api/personal/passwordmodify", {
          uid: this.$jwt(localStorage.getItem("User-Token")).uid,
          upassword: this.password,
        })
        .then((res) => {
          if (res.code == 200) {
            localStorage.removeItem("User-Token");
            this.$message({
              message: "密码修改成功",
              type: "success",
            });
            this.$router.push({
              path: "/login",
            });
          } else {
            this.$message.error({
              message: "密码修改失败",
            });
          }
        });
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  h4 {
    display: flex;
    margin: 0;
    height: 2rem;
    text-align: center;
    color: #fff;
    background-color: #000;
    a {
      flex: 1;
      line-height: 2rem;
    }
    span {
      flex: 8;
      line-height: 2rem;
    }
  }
  .box_center {
    position: relative;
    height: 90vh;
    background-color: rgb(53, 52, 52);
    .box_center_list {
      margin: 0 auto;
      width: 90%;
      height: auto;
      line-height: 5rem;
      overflow: hidden;
      a {
        display: block;
        width: 50%;
        height: 2rem;
        line-height: 2rem;
        color: #fff;
        text-align: center;
        border: 1px solid #e6e6e6;
        border-radius: 0.3rem;
        margin: 1rem auto;
      }
    }
  }
}
</style>